package Dao;

import pojo.Book;

import util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class BookDaoImpl implements BookDao{

	public List<Book> loadAllBooks() {
		List<Book> bl = new ArrayList<Book>();
		String sql="select * from books order by bid";
		PreparedStatement pst =null;
		ResultSet rs = null;
		Connection conn = null;
		Book b =null;
		int m =0;
		try {
			conn=DBUtil.createConnection();
			pst=conn.prepareStatement(sql);
			rs=pst.executeQuery();
			while(rs.next()){
				b= new Book();
				b.setBid(rs.getString("bid"));
				b.setBname(rs.getString("bname"));
				bl.add(b);
			}
			m=pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			DBUtil.close(conn, pst, rs);
		}
		System.out.println(m);
		
		return bl;
	}

}
